﻿using System;
using HMEngine.HMComponents;
using HMEngine.HMObjects;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace HMEngine {
    public sealed class HMGame : Game {
        private readonly GraphicsDeviceManager myGraphics;

        public HMGame(int width, int height) {
            myGraphics = new GraphicsDeviceManager(this) { PreferredBackBufferWidth = width, PreferredBackBufferHeight = height };

            Components.Add(new HMObjectManager(this));
            Components.Add(new HMComponentManager(this));

            Window.AllowUserResizing = true;
            Window.ClientSizeChanged += Window_ClientSizeChanged;
        }

        private void Window_ClientSizeChanged(object sender, EventArgs e) {
            myGraphics.PreferredBackBufferWidth = Window.ClientBounds.Width;
            myGraphics.PreferredBackBufferHeight = Window.ClientBounds.Height;
        }

        protected override void Update(GameTime gameTime) {
            KeyboardState kState = Keyboard.GetState();
            if (kState.IsKeyDown(Keys.F)) {
                myGraphics.ToggleFullScreen();
            }

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime) {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            base.Draw(gameTime);
        }
    }
}